// // 设置院,系,班级 级联数据
// import createCollegeData from '@/utils/college-cascader.js'
// const { collegeId, professionId, classId, collegeOptions, professionOptions, classOptions } =
//   createCollegeData()
// form.value.collegeId = collegeId
// form.value.professionId = professionId
// form.value.classId = classId

import { ref, watchEffect } from 'vue'
import { initDic, $dic } from '@/api/dic.js'

export function createCollegeData() {
  const dic = ref({
    collegeList: [],
  })
  initDic(dic)
  const collegeId = ref('')
  const professionId = ref('')
  const classId = ref('')

  const collegeOptions = computed(() => {
    return dic.value.collegeList.filter((item) => {
      return item.nodeType === 'college'
    })
  })
  const professionOptions = computed(() => {
    return dic.value.collegeList.filter((item) => {
      return item.nodeType === 'profession' && item.pid === collegeId.value
    })
  })

  const classOptions = ref([])
  watchEffect(() => {
    if (!collegeId.value || !professionId.value) {
      classOptions.value = []
      return
    }
    const sendData = {
      collegeId: collegeId.value,
      professionId: professionId.value,
      pageNum: 1,
      pageSize: 10000,
    }
    $dic.classList(sendData).then((res) => {
      classOptions.value = res.rows
    })
  })

  return {
    collegeId,
    professionId,
    classId,
    collegeOptions,
    professionOptions,
    classOptions,
  }
}
